#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s)
    {
        if (s.empty())
            return 0;
        int global_max_length = 1;
        string current_string = "";
        current_string += s[0];
        for (int i = 1; i < s.size(); i++) {
            int repeat_index = current_string.find(s[i], 0);
            if (repeat_index == string::npos) {
                current_string += s[i];
            } else {
                current_string.erase(0, repeat_index + 1);
                current_string += s[i];
            }
            if (global_max_length < current_string.size())
                global_max_length = current_string.size();
        }
        return global_max_length;
    }
};

int main(int argc, char const* argv[])
{
    Solution temp;
    cout << temp.lengthOfLongestSubstring("abcabcbb") << endl;
    cout << temp.lengthOfLongestSubstring("pwwkew") << endl;
    cout << temp.lengthOfLongestSubstring("dvdf") << endl;
    cout << temp.lengthOfLongestSubstring("njdsfhuidsafhs") << endl;
    return 0;
}

